home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 44 / PC Actual CD 44.iso / Linux / Cygwin / full.exe / Disk1 / data1.cab / Tools / H-i586-cygwin32 / i586-cygwin32 / include / stdio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-04  |  9.7 KB  |  310 lines

  1. /*
  2.  * Copyright (c) 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Berkeley.  The name of the
  11.  * University may not be used to endorse or promote products derived
  12.  * from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  *
  17.  *    @(#)stdio.h    5.3 (Berkeley) 3/15/86
  18.  */
  19.  
  20. /*
  21.  * NB: to fit things in six character monocase externals, the
  22.  * stdio code uses the prefix `__s' for stdio objects, typically
  23.  * followed by a three-character attempt at a mnemonic.
  24.  */
  25.  
  26. #ifndef _STDIO_H_
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #define    _STDIO_H_
  31.  
  32. #include "_ansi.h"
  33.  
  34. #define    _FSTDIO            /* ``function stdio'' */
  35.  
  36. #define __need_size_t
  37. #include <stddef.h>
  38.  
  39. #define __need___va_list
  40. #include <stdarg.h>
  41.  
  42. /*
  43.  * <sys/reent.h> defines __sFILE, _fpos_t.
  44.  * They must be defined there because struct _reent needs them (and we don't
  45.  * want reent.h to include this file.
  46.  */
  47.  
  48. #include <sys/reent.h>
  49.  
  50. typedef _fpos_t fpos_t;
  51.  
  52. typedef struct __sFILE FILE;
  53.  
  54. #define    __SLBF    0x0001        /* line buffered */
  55. #define    __SNBF    0x0002        /* unbuffered */
  56. #define    __SRD    0x0004        /* OK to read */
  57. #define    __SWR    0x0008        /* OK to write */
  58.     /* RD and WR are never simultaneously asserted */
  59. #define    __SRW    0x0010        /* open for reading & writing */
  60. #define    __SEOF    0x0020        /* found EOF */
  61. #define    __SERR    0x0040        /* found error */
  62. #define    __SMBF    0x0080        /* _buf is from malloc */
  63. #define    __SAPP    0x0100        /* fdopen()ed in append mode - so must  write to end */
  64. #define    __SSTR    0x0200        /* this is an sprintf/snprintf string */
  65. #define    __SOPT    0x0400        /* do fseek() optimisation */
  66. #define    __SNPT    0x0800        /* do not do fseek() optimisation */
  67. #define    __SOFF    0x1000        /* set iff _offset is in fact correct */
  68. #define    __SMOD    0x2000        /* true => fgetline modified _p text */
  69.  
  70. /*
  71.  * The following three definitions are for ANSI C, which took them
  72.  * from System V, which stupidly took internal interface macros and
  73.  * made them official arguments to setvbuf(), without renaming them.
  74.  * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
  75.  *
  76.  * Although these happen to match their counterparts above, the
  77.  * implementation does not rely on that (so these could be renumbered).
  78.  */
  79. #define    _IOFBF    0        /* setvbuf should set fully buffered */
  80. #define    _IOLBF    1        /* setvbuf should set line buffered */
  81. #define    _IONBF    2        /* setvbuf should set unbuffered */
  82.  
  83. #ifndef NULL
  84. #define    NULL    0L
  85. #endif
  86.  
  87. #define    BUFSIZ    1024
  88. #define    EOF    (-1)
  89.  
  90. #define    FOPEN_MAX    20    /* must be <= OPEN_MAX <sys/syslimits.h> */
  91. #define    FILENAME_MAX    1024    /* must be <= PATH_MAX <sys/syslimits.h> */
  92. #define    L_tmpnam    1024    /* XXX must be == PATH_MAX */
  93. #ifndef _STRICT_ANSI
  94. #define P_tmpdir        "/tmp"
  95. #endif
  96.  
  97. #ifndef SEEK_SET
  98. #define    SEEK_SET    0    /* set file offset to offset */
  99. #endif
  100. #ifndef SEEK_CUR
  101. #define    SEEK_CUR    1    /* set file offset to current plus offset */
  102. #endif
  103. #ifndef SEEK_END
  104. #define    SEEK_END    2    /* set file offset to EOF plus offset */
  105. #endif
  106.  
  107. #define    TMP_MAX        26
  108.  
  109. #define    stdin    (_impure_ptr->_stdin)
  110. #define    stdout    (_impure_ptr->_stdout)
  111. #define    stderr    (_impure_ptr->_stderr)
  112.  
  113. #define _stdin_r(x)    ((x)->_stdin)
  114. #define _stdout_r(x)    ((x)->_stdout)
  115. #define _stderr_r(x)    ((x)->_stderr)
  116.  
  117. /*
  118.  * Functions defined in ANSI C standard.
  119.  */
  120.  
  121. #ifdef __GNUC__
  122. #define __VALIST __gnuc_va_list
  123. #else
  124. #define __VALIST char*
  125. #endif
  126.  
  127. #ifndef _REENT_ONLY
  128. int    _EXFUN(remove, (const char *));
  129. int    _EXFUN(rename, (const char *, const char *));
  130. #endif
  131. char *  _EXFUN(tempnam, (const char *, const char *));
  132. FILE *    _EXFUN(tmpfile, (void));
  133. char *    _EXFUN(tmpnam, (char *));
  134. int    _EXFUN(fclose, (FILE *));
  135. int    _EXFUN(fflush, (FILE *));
  136. FILE *    _EXFUN(freopen, (const char *, const char *, FILE *));
  137. void    _EXFUN(setbuf, (FILE *, char *));
  138. int    _EXFUN(setvbuf, (FILE *, char *, int, size_t));
  139. int    _EXFUN(fprintf, (FILE *, const char *, ...));
  140. int    _EXFUN(fscanf, (FILE *, const char *, ...));
  141. int    _EXFUN(printf, (const char *, ...));
  142. int    _EXFUN(scanf, (const char *, ...));
  143. int    _EXFUN(sscanf, (const char *, const char *, ...));
  144. int    _EXFUN(vfprintf, (FILE *, const char *, __VALIST));
  145. int    _EXFUN(vprintf, (const char *, __VALIST));
  146. int    _EXFUN(vsprintf, (char *, const char *, __VALIST));
  147. int    _EXFUN(fgetc, (FILE *));
  148. char *  _EXFUN(fgets, (char *, int, FILE *));
  149. int    _EXFUN(fputc, (int, FILE *));
  150. int    _EXFUN(fputs, (const char *, FILE *));
  151. int    _EXFUN(getc, (FILE *));
  152. int    _EXFUN(getchar, (void));
  153. char *  _EXFUN(gets, (char *));
  154. int    _EXFUN(putc, (int, FILE *));
  155. int    _EXFUN(putchar, (int));
  156. int    _EXFUN(puts, (const char *));
  157. int    _EXFUN(ungetc, (int, FILE *));
  158. size_t    _EXFUN(fread, (_PTR, size_t _size, size_t _n, FILE *));
  159. size_t    _EXFUN(fwrite, (const _PTR , size_t _size, size_t _n, FILE *));
  160. int    _EXFUN(fgetpos, (FILE *, fpos_t *));
  161. int    _EXFUN(fseek, (FILE *, long, int));
  162. int    _EXFUN(fsetpos, (FILE *, const fpos_t *));
  163. long    _EXFUN(ftell, ( FILE *));
  164. void    _EXFUN(rewind, (FILE *));
  165. void    _EXFUN(clearerr, (FILE *));
  166. int    _EXFUN(feof, (FILE *));
  167. int    _EXFUN(ferror, (FILE *));
  168. void    _EXFUN(perror, (const char *));
  169. #ifndef _REENT_ONLY
  170. FILE *    _EXFUN(fopen, (const char *_name, const char *_type));
  171. int    _EXFUN(sprintf, (char *, const char *, ...));
  172. #endif
  173. #ifndef _STRICT_ANSI
  174. int    _EXFUN(vfiprintf, (FILE *, const char *, __VALIST));
  175. int    _EXFUN(iprintf, (const char *, ...));
  176. int    _EXFUN(fiprintf, (FILE *, const char *, ...));
  177. int    _EXFUN(siprintf, (char *, const char *, ...));
  178. #endif
  179.  
  180. /*
  181.  * Routines in POSIX 1003.1.
  182.  */
  183.  
  184. #ifndef _STRICT_ANSI
  185. #ifndef _REENT_ONLY
  186. FILE *    _EXFUN(fdopen, (int, const char *));
  187. #endif
  188. int    _EXFUN(fileno, (FILE *));
  189. int    _EXFUN(getw, (FILE *));
  190. int    _EXFUN(pclose, (FILE *));
  191. FILE *  _EXFUN(popen, (const char *, const char *));
  192. int    _EXFUN(putw, (int, FILE *));
  193. void    _EXFUN(setbuffer, (FILE *, char *, int));
  194. int    _EXFUN(setlinebuf, (FILE *));
  195. #endif
  196.  
  197. /*
  198.  * Recursive versions of the above.
  199.  */
  200.  
  201. FILE *    _EXFUN(_fdopen_r, (struct _reent *, int, const char *));
  202. FILE *    _EXFUN(_fopen_r, (struct _reent *, const char *, const char *));
  203. int    _EXFUN(_getchar_r, (struct _reent *));
  204. char *    _EXFUN(_gets_r, (struct _reent *, char *));
  205. int    _EXFUN(_iprintf_r, (struct _reent *, const char *, ...));
  206. int    _EXFUN(_mkstemp_r, (struct _reent *, char *));
  207. char *    _EXFUN(_mktemp_r, (struct _reent *, char *));
  208. void    _EXFUN(_perror_r, (struct _reent *, const char *));
  209. int    _EXFUN(_printf_r, (struct _reent *, const char *, ...));
  210. int    _EXFUN(_putchar_r, (struct _reent *, int));
  211. int    _EXFUN(_puts_r, (struct _reent *, const char *));
  212. int    _EXFUN(_remove_r, (struct _reent *, const char *));
  213. int    _EXFUN(_rename_r, (struct _reent *,
  214.                const char *_old, const char *_new));
  215. int    _EXFUN(_scanf_r, (struct _reent *, const char *, ...));
  216. int    _EXFUN(_sprintf_r, (struct _reent *, char *, const char *, ...));
  217. char *    _EXFUN(_tempnam_r, (struct _reent *, char *, char *));
  218. FILE *    _EXFUN(_tmpfile_r, (struct _reent *));
  219. char *    _EXFUN(_tmpnam_r, (struct _reent *, char *));
  220. int    _EXFUN(_vfprintf_r, (struct _reent *, FILE *, const char *, __VALIST));
  221. int    _EXFUN(_vprintf_r, (struct _reent *, const char *, __VALIST));
  222. int    _EXFUN(_vsprintf_r, (struct _reent *, char *, const char *, __VALIST));
  223.  
  224. /*
  225.  * Routines internal to the implementation.
  226.  */
  227.  
  228. int    _EXFUN(__srget, (FILE *));
  229. int    _EXFUN(__swbuf, (int, FILE *));
  230.  
  231. /*
  232.  * Stdio function-access interface.
  233.  */
  234.  
  235. #ifndef _STRICT_ANSI
  236. FILE    *_EXFUN(funopen,(const _PTR _cookie,
  237.         int (*readfn)(_PTR _cookie, char *_buf, int _n),
  238.         int (*writefn)(_PTR _cookie, const char *_buf, int _n),
  239.         fpos_t (*seekfn)(_PTR _cookie, fpos_t _off, int _whence),
  240.         int (*closefn)(_PTR _cookie)));
  241.  
  242. #define    fropen(cookie, fn) funopen(cookie, fn, (int (*)())0, (fpos_t (*)())0, (int (*)())0)
  243. #define    fwopen(cookie, fn) funopen(cookie, (int (*)())0, fn, (fpos_t (*)())0, (int (*)())0)
  244. #endif
  245.  
  246. /*
  247.  * The __sfoo macros are here so that we can 
  248.  * define function versions in the C library.
  249.  */
  250. #define    __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
  251. #ifdef _never /* __GNUC__ */
  252. /* If this inline is actually used, then systems using coff debugging
  253.    info get hopelessly confused.  21sept93 rich@cygnus.com.  */
  254. static __inline int __sputc(int _c, FILE *_p) {
  255.     if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
  256.         return (*_p->_p++ = _c);
  257.     else
  258.         return (__swbuf(_c, _p));
  259. }
  260. #else
  261. /*
  262.  * This has been tuned to generate reasonable code on the vax using pcc
  263.  */
  264. #define    __sputc(c, p) \
  265.     (--(p)->_w < 0 ? \
  266.         (p)->_w >= (p)->_lbfsize ? \
  267.             (*(p)->_p = (c)), *(p)->_p != '\n' ? \
  268.                 (int)*(p)->_p++ : \
  269.                 __swbuf('\n', p) : \
  270.             __swbuf((int)(c), p) : \
  271.         (*(p)->_p = (c), (int)*(p)->_p++))
  272. #endif
  273.  
  274. #define    __sfeof(p)    (((p)->_flags & __SEOF) != 0)
  275. #define    __sferror(p)    (((p)->_flags & __SERR) != 0)
  276. #define    __sclearerr(p)    ((void)((p)->_flags &= ~(__SERR|__SEOF)))
  277. #define    __sfileno(p)    ((p)->_file)
  278.  
  279. #define    feof(p)        __sfeof(p)
  280. #define    ferror(p)    __sferror(p)
  281. #define    clearerr(p)    __sclearerr(p)
  282.  
  283. #if 0 /*ndef _STRICT_ANSI - FIXME: must initialize stdio first, use fn */
  284. #define    fileno(p)    __sfileno(p)
  285. #endif
  286.  
  287. #ifndef lint
  288. #define    getc(fp)    __sgetc(fp)
  289. #define putc(x, fp)    __sputc(x, fp)
  290. #endif /* lint */
  291.  
  292. #define    getchar()    getc(stdin)
  293. #define    putchar(x)    putc(x, stdout)
  294.  
  295. #ifndef _STRICT_ANSI
  296. /* fast always-buffered version, true iff error */
  297. #define    fast_putc(x,p) (--(p)->_w < 0 ? \
  298.     __swbuf((int)(x), p) == EOF : (*(p)->_p = (x), (p)->_p++, 0))
  299.  
  300. #define    L_cuserid    9        /* posix says it goes in stdio.h :( */
  301. #ifdef __CYGWIN32__
  302. #define L_ctermid       16
  303. #endif
  304. #endif
  305.  
  306. #ifdef __cplusplus
  307. }
  308. #endif
  309. #endif /* _STDIO_H_ */
  310.